import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-05-13
 * Time: 18:53
 */
//给定一个有序整型数组, 实现二分查找
public class test {
    public static int fun(int[] arr,int n){
        int left=arr.length-1;
        int right=0;
        int p=0;
        while(right<=left){
            p=(left+right)/2;
            if(arr[p]==n)
                return p;
            if(n<arr[p])
                left=p-1;
            else
                right=p+1;
        }
        return -1;
    }
    public static void main(String[] args){
        int[] arr=new int[101];
        for (int i = 0; i < arr.length; i++) {
            arr[i]=i;
        }
        System.out.println("请输入要查找的数");
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int i=fun(arr,n);
        if(i>0)
            System.out.println("下标为"+i);
        else
            System.out.println("找不到该数");
    }
}
